// pages/search/search.js
Page({
    mixins: [require('../../mixin/common')],
    data: {
      inputShowed: false,
      inputVal: '',
      wordList:['nihao','湖南','夏天'],
      subjects:[]
    },
    query(options){
      let that =this
      console.log(options);
      this.setData({inputVal:''})
  
      let db =wx.cloud.database()
      db.collection('dmsj')
          .get({
            success:(res)=>{
                console.log(res);
                let subjects = that.data.subjects
                subjects = subjects.concat(res.data[0].dongman)
                subjects = subjects.concat(res.data[0].rebo)
              that.setData({
                subjects:subjects
              })
              let tmpArray = this.data.subjects.filter((value,index,array)=>{
                return value.title.indexOf(key)!=-1
              })
              console.log(tmpArray);
              that.setData({
                subjects:tmpArray
              })
              
            }
          })
    },
    showInput() {
      this.setData({
        inputShowed: true,
      });
    },
    hideInput(options) {
      this.query(options)
      this.setData({
        inputVal: '',
        inputShowed: false,
      });
    },
    clearInput() {
      this.setData({
        inputVal: '',
      });
    },
    inputTyping(e) {
      this.setData({
        inputVal: e.detail.value,
      });
      let db=wx.cloud.database()
      let searchCollection=db.collection('search')
      searchCollection.get().then(res=>{
        console.log(res.data[0].subjects);
        this.setData({
          wordList:res.data[0].subjects
        })
      })
    },
  });